package com.swsc.solarverse.dao.mapper.forward;

import com.swsc.solarverse.common.mybatis.BasePlusMapper;
import com.swsc.solarverse.dao.entity.forward.ForwardSubmatrixLeRecordDO;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-07-06
 */
@org.apache.ibatis.annotations.Mapper
public interface ForwardSubmatrixLeRecordMapper extends BasePlusMapper<ForwardSubmatrixLeRecordDO> {

    @org.apache.ibatis.annotations.Select(value = "SELECT max(diagnose_time) FROM solar_forward_submatrix_le_record WHERE organ_no = #{organNo}")
    LocalDateTime maxDiagnoseTime(@org.apache.ibatis.annotations.Param("organNo") Integer organNo);
    @org.apache.ibatis.annotations.Select(value = "SELECT max(diagnose_time) FROM solar_forward_submatrix_le_record_yesterday WHERE organ_no = #{organNo}")
    LocalDateTime maxDiagnoseTimeYesterday(@org.apache.ibatis.annotations.Param("organNo") Integer organNo);
    @org.apache.ibatis.annotations.Select(value = "SELECT max(diagnose_time) FROM solar_forward_submatrix_le_record_his WHERE organ_no = #{organNo}")
    LocalDateTime maxHisDiagnoseTime(@org.apache.ibatis.annotations.Param("organNo") Integer organNo);
    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_submatrix_le_record (`id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.deviceName}, #{item.deviceCode}, #{item.submatrix}, #{item.submatrixStringNum}, #{item.diagnoseTime}, #{item.avgI}, #{item.avgU}, #{item.lossI}, #{item.lossU}, #{item.lossP}, #{item.lossE}, #{item.lowINum}, #{item.lowUNum}, #{item.lowIUNum},  #{item.createTime})",
            "</foreach>",
            "</script>"
    })
    int insertIgnoreBatch(List<ForwardSubmatrixLeRecordDO> list);
    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_submatrix_le_record (`id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.deviceName}, #{item.deviceCode}, #{item.submatrix}, #{item.submatrixStringNum}, #{item.diagnoseTime}, #{item.avgI}, #{item.avgU}, #{item.lossI}, #{item.lossU}, #{item.lossP}, #{item.lossE}, #{item.lowINum}, #{item.lowUNum}, #{item.lowIUNum},  #{item.createTime})",
            "</foreach>",
            "</script>"
    })
    int insertIgnoreBatchYesterday(List<ForwardSubmatrixLeRecordDO> list);

    @org.apache.ibatis.annotations.Delete(value = {
            "<script>",
            "DELETE FROM solar_forward_submatrix_le_record_his WHERE `diagnose_time` &lt;= #{diagnoseTime}",
            "</script>"
    })
    int deleteHisByDataTime(@org.apache.ibatis.annotations.Param("diagnoseTime")String diagnoseTime);

    @org.apache.ibatis.annotations.Insert(value = {
            "<script>",
            "INSERT INTO solar_forward_submatrix_le_record_his (`id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time`) " +
                    "(SELECT `id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time` FROM solar_forward_submatrix_le_record)",
            "</script>"
    })
    int backupDiagnoseRecord();

    @org.apache.ibatis.annotations.Select(value = "SELECT `id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time` FROM solar_forward_submatrix_le_record_his WHERE tenant_no = #{tenantNo} AND organ_no = #{organNo} AND diagnose_time = #{diagnoseTime} AND (low_i > 0.5 or low_u > 0.5)")
    List<ForwardSubmatrixLeRecordDO> diagnoseRecordHisResult(@org.apache.ibatis.annotations.Param("tenantNo")Integer tenantNo,
                                                                  @org.apache.ibatis.annotations.Param("organNo")Integer organNo,
                                                                  @org.apache.ibatis.annotations.Param("diagnoseTime")LocalDateTime diagnoseTime);
    @org.apache.ibatis.annotations.Select(value = "SELECT `id`,`tenant_no`,`organ_no`,`device_name`,`device_code`,`submatrix`,`submatrix_string_num`,`diagnose_time`,`avg_i`,`avg_u`,`loss_i`,`loss_u`,`loss_p`,`loss_e`,`low_i_num`,`low_u_num`,`low_iu_num`,`create_time` FROM solar_forward_submatrix_le_record_yesterday WHERE tenant_no = #{tenantNo} AND organ_no = #{organNo} AND diagnose_time = #{diagnoseTime} AND (low_i > 0.5 or low_u > 0.5)")
    List<ForwardSubmatrixLeRecordDO> diagnoseRecordYesterdayLow(@org.apache.ibatis.annotations.Param("tenantNo")Integer tenantNo,
                                                                     @org.apache.ibatis.annotations.Param("organNo")Integer organNo,
                                                                     @org.apache.ibatis.annotations.Param("diagnoseTime")LocalDateTime diagnoseTime);

    @org.apache.ibatis.annotations.Select(value = "SELECT max(diagnose_time) FROM solar_forward_submatrix_le_record WHERE organ_no = #{organNo} and diagnose_time >= #{diagnoseTimeGe} and diagnose_time < #{diagnoseTimeLt}")
    LocalDateTime maxDiagnoseTimeByRange(@org.apache.ibatis.annotations.Param("organNo") Integer organNo,
                                       @org.apache.ibatis.annotations.Param("diagnoseTimeGe") LocalDateTime diagnoseTimeGe,
                                       @org.apache.ibatis.annotations.Param("diagnoseTimeLt") LocalDateTime diagnoseTimeLt);
    @org.apache.ibatis.annotations.Select(value = "SELECT min(diagnose_time) FROM solar_forward_submatrix_le_record WHERE organ_no = #{organNo} and diagnose_time >= #{diagnoseTimeGe} and diagnose_time < #{diagnoseTimeLt}")
    LocalDateTime minDiagnoseTimeByRange(@org.apache.ibatis.annotations.Param("organNo") Integer organNo,
                                       @org.apache.ibatis.annotations.Param("diagnoseTimeGe") LocalDateTime diagnoseTimeGe,
                                       @org.apache.ibatis.annotations.Param("diagnoseTimeLt") LocalDateTime diagnoseTimeLt);
}
